home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
amiga
/
gui
/
prcgntn1.lha
/
Precognition
/
source
/
AmigaMem.c
next >
Wrap
C/C++ Source or Header
|
1992-12-23
|
1KB
|
88 lines
#include "AmigaMem.h"
#include <exec/memory.h>
#include <string.h>
#include <proto/exec.h>
#include "minmax.h"
void* Amalloc( ULONG size )
{
ULONG *base;
if (base = AllocMem( size+4, MEMF_CLEAR | MEMF_PUBLIC ))
{
base[0] = size+4;
return (void*) &base[1];
}
else
return NULL;
}
void* Acalloc( ULONG size, ULONG number )
{
return Amalloc( size*number );
}
char* Astrdup( const char* string )
{
char* dup;
int len;
if (string==NULL) return NULL;
len = strlen( string );
if (dup = Amalloc(len+1))
{
strcpy(dup,string);
}
return dup;
}
void Afree( void* mem )
{
ULONG *base;
if (mem)
{
base = ((ULONG*)mem) -1;
FreeMem( base, base[0] );
}
}
ULONG Asizeof( void* buf )
{
ULONG *base;
if (buf)
{
base = ((ULONG*)buf) -1;
return base[0];
}
else
return 0;
}
void *Arealloc( void *oldbuf, ULONG newsize )
{
void *newbuf = Amalloc( newsize );
ULONG minsize, oldsize;
if (newbuf)
{
oldsize = (oldbuf) ? Asizeof(oldbuf) : 0;
minsize = MIN(oldsize,newsize);
memcpy( newbuf, oldbuf, minsize );
Afree(oldbuf);
return newbuf;
}
else
return NULL;
}